<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Error extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->library('Mydatetime');
		$this->load->library('session');
		$this->load->model('error/error_model');
		$this->load->language('error/error', 'vietnam');
        $this->load->language('common', 'vietnam');
	}
	
	function _loadHeader($title = '')
	{
		$header = array();
		$header['title'] = $title;
		
		$header['username'] = '';
		$header['userid'] = '';
		$header['access'] = '';
        
		if($this->session->userdata('uname'))
		{
			$header['username'] = $this->session->userdata('username');
			$header['userid'] = $this->session->userdata('uid');
			$header['access'] = $this->session->userdata('access');
		}
		
		$this->load->view('header_view', $header);
	}
	
	function _loadLeftmenu()
	{
        $data = array();
        $common_lang = $this->lang->line('common_lang');
        $data['common_lang'] = $common_lang;
        
        $data['userid'] = $this->session->userdata('uid');
		$data['username'] = $this->session->userdata('username');
		$this->load->view('leftmenu_view', $data);
	}
	
	function _loadFooter()
	{
		$this->load->view('footer_view');
	}
	
    function index($page=1)
	{
        if(!$this->session->userdata('username'))
        {
            redirect(site_url('login'));
            die();
        }
        $data = array();
        $uid = $this->session->userdata('uid');
        $error_lang = $this->lang->line('error_lang');
        $numrow = (int)$this->input->get('numrow') > 0 ? (int)$this->input->get('numrow') : 20;
        $page = (int)$this->input->get('page') > 0 ? (int)$this->input->get('page') : 1;
        
        $error = $this->error_model->ww_get_error_log_info($numrow, $page);

        $data['lsterror'] = $error['0'];
        $data['total'] = $error['1']['0']['total'];
        $data['page'] = $page;
        $data['numrow'] = $numrow;
        $data['max_page'] = ceil($data['total']/$numrow);
        $data['error_lang'] = $error_lang;
        
        // header
        $this->_loadHeader('Quản lí lỗi');
        
        // left menu
        $this->_loadLeftmenu();
        
        // content
        $this->load->view('error/lst_error_view', $data);
        
        // footer
        $this->_loadFooter();
    }
    
    function detail($errorid)
    {
        $data = array();
        $errorid = 1;
        // header
        $this->_loadHeader('Chi tiết mã lỗi '.$errorid);
        
        // left menu
        $this->_loadLeftmenu();
        
        // content
        $this->load->view('error/errordetail_view', $data);
        
        // footer
        $this->_loadFooter();
    }
}